#include "strategyupdown.h"
#include"gamecontrol.h"
#include<QDebug>

StrategyUpdown::StrategyUpdown()
{
    this->setPos(1180,400);
    this->setPixmap(QPixmap(":/1/Image/StrategyUpdown.png"));
    movingdown = true;
}

void StrategyUpdown::collision()
{
    QRectF mManBlueRect = QRectF(GameControl::Instance()->getManBlue().x()+35,GameControl::Instance()->getManBlue().y()+25,35,50);

    QRectF mManRedRect = QRectF(GameControl::Instance()->getManRed().x()+25,GameControl::Instance()->getManRed().y()+25,40,50);

    for(int i=0;i<GameControl::Instance()->mSwitchUpdown.size();i++)
    {
        if(mManBlueRect.intersects(GameControl::Instance()->mSwitchUpdown[i]->_Rect)
            || mManRedRect.intersects(GameControl::Instance()->mSwitchUpdown[i]->_Rect))
        {
            GameControl::Instance()->mSwitchUpdown[i]->setY(GameControl::Instance()->mSwitchUpdown[i]->y1);

            if(this->y() == 525)
            {
                movingdown = false;
            }

            if(movingdown)
            {
                this->moveBy(0,1);
            }
            else if(!movingdown)
            {
                this->moveBy(0,-1);
                if(this->y() == 350)
                {
                    movingdown = true;
                }
            }
        }
        else
        {
            GameControl::Instance()->mSwitchUpdown[i]->setPos(GameControl::Instance()->mSwitchUpdown[i]->_xy);
        }
    }
}


